package app.beit.finportal.service;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import app.beit.finportal.bean.WebboardBean;
import app.beit.finportal.dao.WebboardDao;
import app.beit.finportal.entity.Webboard;
import app.beit.finportal.service.convert.WebboardConvert;

public class WebboardService {

	@Autowired
	private WebboardDao webboardDao;
	
	public List<WebboardBean> getAllPost() throws Exception{
		final List<Webboard> entities = this.webboardDao.getAllPost();
		if(entities != null && entities.size() > 0){
			return WebboardConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public List<WebboardBean> getAllPostAtMainPage() throws Exception{
		final List<Webboard> entities = this.webboardDao.getAllPostAtMainPage();
		if(entities != null && entities.size() > 0){
			return WebboardConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public WebboardBean getWebboardById(String id) throws Exception{
		final Webboard entity = this.webboardDao.getWebboardById(id);
		if(entity != null){
			return WebboardConvert.entityToBean(entity);
		}
		return null;
	}
	
	public void add(final WebboardBean bean) throws Exception{
		this.webboardDao.add(WebboardConvert.beanToEntity(bean));
	}
	
	public void update(final WebboardBean bean) throws Exception{
		this.webboardDao.update(WebboardConvert.beanToEntity(bean));
	}
	
	public void delete(final WebboardBean bean) throws Exception{
		this.webboardDao.delete(WebboardConvert.beanToEntity(bean));
	}
}
